package com.hnu.store.controller;

import com.hnu.store.entity.SearchRecord;
import com.hnu.store.service.ISearchRecordService;
import com.hnu.store.utils.JsonResult;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin

@RequestMapping("searchRecord")
public class SearchRecordController extends BaseController{
    @Autowired
    private ISearchRecordService searchRecordService;

    //  添加搜索记录
    @RequestMapping("addSearchRecord")
    public JsonResult addSearchRecord(SearchRecord searchRecord){
        searchRecordService.addSearchRecord(searchRecord);

        return new JsonResult(OK);
    }

    //  删除搜索记录
    @RequestMapping("deleteSearchRecord")
    public JsonResult deleteSearchRecord(SearchRecord searchRecord){
        searchRecordService.deleteSearchRecord(searchRecord);

        return new JsonResult(OK);
    }

    //  获取全部搜索记录
    @RequestMapping("getSearchRecord")
    public JsonResult getSearchRecord(){
        ArrayList<SearchRecord> searchRecords = searchRecordService.getSearchRecord();
        JsonResult result = new JsonResult(OK);
        result.addData("searchRecords",searchRecords);
        return result;
    }
}
